<script setup lang="ts">
import { nextTick, onBeforeUnmount, onMounted, ref, type Ref } from 'vue'
import PerfectScrollbar from 'perfect-scrollbar'

const root = ref() as Ref<HTMLDivElement>

let p: PerfectScrollbar | null

onMounted(() => {
  p = new PerfectScrollbar(root.value)
})

onBeforeUnmount(() => {
  p?.destroy()
  p = null
})

function scrollTop(y: number) {
  root.value.scrollTop = y
}

defineExpose({ scrollTop })
</script>
<template>
  <div ref="root" class="scroll-view" style="position: relative">
    <slot />
  </div>
</template>
